package com.mxchip.livestar.ui.network.wifi.widget;

import android.content.Context;
import android.widget.EditText;

import com.mxchip.livestar.R;
import com.mxchip.livestar.ui.network.wifi.widget.base.Dialog;


public class ConnectDialog extends Dialog {
    public ConnectDialog(Context context) {
        super(context);
    }

    @Override
    protected int getLayout() {
        return R.layout.dialog_connect;
    }

    public void onCancelClick() {
        dismiss();
    }

    public interface OnConnectDialogListener {
        void onConfirm(String password);
    }

    @Override
    protected void initView() {
        super.initView();
        EditText password = (EditText) inflate.findViewById(R.id.et_password);
        inflate.findViewById(R.id.tv_cancel).setOnClickListener(v -> onCancelClick());
        inflate.findViewById(R.id.tv_confirm).setOnClickListener(v -> onConfirmClick(password.getText().toString()));
    }

    OnConnectDialogListener onConnectDialogListener;

    public ConnectDialog setOnConnectDialogListener(OnConnectDialogListener onConnectDialogListener) {
        this.onConnectDialogListener = onConnectDialogListener;
        return this;
    }

    public void onConfirmClick(String password) {
        dismiss();
        if (onConnectDialogListener != null)
            onConnectDialogListener.onConfirm(password);
    }
}
